PHP API

IceWarp Server offers for integration with web applications also PHP API. There are implemented usual methods of standard IceWarp Server objects (it is same as for the COM object i.e. the same documentation applies). It is suitable to use PHP API for those solutions that are not to be used on Windows only.

The basic difference lies in the fact that apiobjectcall is used instead of the COM object. Also, in contrast to the COM object that supports strings in Unicode format, apiobjectcall supports UTF-8 (that is easily usable in PHP). In the practice, this is advantageous when setting values with non-ASCII characters into objects features e.g. description or name.

How to Include PHP API into Script

To use PHP API, it is necessary to include appropriate scripts. There is a special script file for every IceWarpServer object. These can be found within the directory for shared libraries. The path to this directory is added to PHP configuration (end of the php.ini file) the icewarp_sharedlib_path variable.

Example:

define( SHAREDLIB_PATH, get_cfg_var( 'icewarp_sharedlib_path' ) );

require_once( SHAREDLIB_PATH . 'api/api.php' );

require_once( SHAREDLIB_PATH . 'api/domain.php' );

How to Initialize New IceWarpServer Object

It is similar to the way how the COM object is initialized. Therefore it is very easy to change your current scripts to use PHP API instead of COM. Please note that object names are slightly different IceWarpServer.AccountObject becomes IceWarpAccount class and so on (the same pattern applies for other objects).

Example:

$domainObj = new IceWarpDomain();

if ( $apiObj = new IceWarpAPI() )

{

    echo [OK] API init done";

}

else

{

    die ( '[CRITICAL] IceWarp API could not be initialized.' );

}

Differences from COM Usage

Besides of the difference mentioned in the previous section, the method of New was renamed to New_ in PHP API.

It is also possible to use special method of FunctionCall( $funcName, $param1, $param5 ) which provides the alternative that is suitable for calling of various methods.

Example:

function DomainWorker( $action, $domainName, $params = array() )

{

    $domainObj = &$GLOBALS['domainObj'];

    $exists = $domainObj->Open( $domainName ); // does domain exists?

    if ( !$exists && $action == 'add' ) // not exists and want to add it

    {

        echo " Adding domain {$domainName}: ";

        $domainObj->New_( $domainName ); // only defines action as create

        // set some domain properties

        empty( $params[0] ) ?

null : $domainObj->SetProperty( 'D_AdminEmail', $params[0] );

        empty( $params[1] ) ?

null : $domainObj->FunctionCall( 'SetProperty', 'D_description', $params[1] );

        if ( $domainObj->Save() ) // actions are performed at this point

        {

            echo 'domain saved';

        }

        else

        {

            $e = $domainObj->LastErr; // get last action error code

            echo "save failed[$e]"; // codes in api/delphi/apiconst.pas

        }

    }

}

DomainWorker( 'add', 'iwdemo.com', array( 'admin@iwdemo.com', 'robot' ) );

Note: You can copy & paste all above examples into single working PHP example script.